home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / elisp / dylan-params.el < prev   
Encoding:
Text File  |  1995-03-15  |  14.5 KB  |  337 lines  |  [TEXT/ttxt]

  1. ;;; dylan-params v. 0.02
  2. ;;; Nick Kramer (nkramer@cs.cmu.edu)
  3.  
  4. ;;; Copyright (C) 1994  Carnegie Mellon University
  5.  
  6. ;;; A quick hack to provide a parameter summary for methods in the
  7. ;;; Dylan Interim Reference Manual (DIRM). Comes in two flavors:
  8. ;;; dylan-show-method-params, which is meant to be called explicitly,
  9. ;;; and auto-display-method-params, which is meant to be called
  10. ;;; automatically.
  11.  
  12. ;;; dylan-show-method-params gets the method name from the cursor
  13. ;;; position. If an identifier can't be found near the cursor or if a
  14. ;;; prefix argument was supplied, this function asks the user for a
  15. ;;; method name. It displays a parameter list in the echo area, or
  16. ;;; will open up a new window if the parameter list is long.
  17. ;;; (Currently the only "long" param lists are for,
  18. ;;; forward-iteration-protocol, and table-protocol. Ok, for isn't
  19. ;;; actually a method, but it's handy to have in there) If the method
  20. ;;; name is unknown, it will complain.
  21.  
  22. ;;; auto-display-method-params is meant to be bound to the open paren
  23. ;;; key '('. If there is no space between a method name and the open
  24. ;;; paren, it will automatically display the parameter list in the
  25. ;;; echo area. This function is meant to be unobtrusive; if a method
  26. ;;; name is not found or if the method name is unknown, nothing is
  27. ;;; done. Similarly, it will *always* display in the echo area, never
  28. ;;; popping up another window, even if the parameter list is long.
  29.  
  30. ;;; To use, put these lines in your .emacs file:
  31.  
  32. ;;; (autoload 'dylan-show-method-params "dylan-params"
  33. ;;;       "Provide a Dylan method parameter summary." t)
  34. ;;; 
  35. ;;; (autoload 'auto-display-method-params "dylan-params"
  36. ;;; "When bound to '(', automatically provides Dylan method param summaries.")
  37. ;;; 
  38. ;;; (setq dylan-mode-hook '(lambda ()
  39. ;;;              (local-set-key "("    'auto-display-method-params)))
  40.  
  41. ;;; (Remove the ;;;) This automatically loads both functions whenever
  42. ;;; you need them, and binds the open paren key to
  43. ;;; auto-display-method-params. This sample .emacs code assumes that
  44. ;;; you're using Robert Stockton's Dylan mode; if you aren't, you
  45. ;;; should be.
  46.  
  47. ;;; This file contains parameter summaries of every method in the
  48. ;;; DIRM, as well as a description of for.  One can extend the summary
  49. ;;; list by appending to dylan-method-list; see end of file for a big
  50. ;;; example.  In the future, something less brain dead might be used,
  51. ;;; but in the mean time, that's what we have.
  52.  
  53. ;;; Questions, comments, bugs, flames to nkramer@cs.cmu.edu.
  54. ;;; Disclaimer follows.
  55.  
  56. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  57.  
  58. ;;; This program is free software; you can redistribute it and/or modify
  59. ;;; it under the terms of the GNU General Public License as published by
  60. ;;; the Free Software Foundation; either version 1, or (at your option)
  61. ;;; any later version.
  62. ;;;
  63. ;;; This program is distributed in the hope that it will be useful,
  64. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  65. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  66. ;;; GNU General Public License for more details.
  67. ;;;
  68. ;;; A copy of the GNU General Public License can be obtained from this
  69. ;;; program's author (send electronic mail to nkramer@cs.cmu.edu) or from
  70. ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
  71. ;;; 02139, USA.
  72.  
  73. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  74.  
  75. (defvar dylan-id-chars "-a-zA-Z0-9!&*<>=|^$%@_+~?/")
  76. ;; Derived from Bill Chiles' patterns
  77.  
  78. ;;;;;;;;;;;;;;;;;;;;;;;;
  79.  
  80. (defun dylan-show-method-params (prefix)
  81. "Provide a Dylan method parameter summary.
  82. Finds the method name under the cursor, and tells about its arguments.
  83. If an identifier is not found or if a prefix argument is given, it asks 
  84. the user for a method name. If the param list is long, it'll display 
  85. in a separate buffer like Help does. Otherwise, it'll display in the 
  86. echo area."
  87.   (interactive "p")
  88.   (save-excursion
  89.     (skip-chars-backward dylan-id-chars)
  90.     (let* ((start (point))
  91.        (execute-this (skip-chars-forward dylan-id-chars))
  92.        (end (point))
  93.        (id (if (or (= start end)
  94.                (/= prefix 1))
  95.            (read-string "Method name: ")
  96.          (downcase (buffer-substring start end)))))
  97.       (dylan-display-method-arg-string id)
  98. )))
  99.  
  100. ;;;;;;;;;;;;;;;;;;;;;;;;
  101.  
  102. (defun auto-display-method-params ()
  103.   "When bound to '(', automatically provides Dylan method param summaries.
  104. Is silent if a method name can't be found or if the method name is unknown;
  105. never opens up additional windows."
  106.   (interactive)
  107.   (save-excursion
  108.     (skip-chars-backward dylan-id-chars)
  109.     (let* ((start (point))
  110.        (execute-this (skip-chars-forward dylan-id-chars))
  111.        (end (point))
  112.        (id (downcase (buffer-substring start end))))
  113.       (dylan-display-method-arg-string id t t)))
  114.   (insert "(")
  115. )
  116.  
  117. ;;;;;;;;;;;;;;;;;;;;;;;;
  118.  
  119. (defun dylan-display-method-arg-string (id &optional disallow-long-doc-strings 
  120.                     suppress-errors)
  121.   (let* ((assoc-answer    (assoc id dylan-method-list))
  122.      (method-name     (car assoc-answer))
  123.      (arg-string      (car (cdr assoc-answer)))
  124.      (result-string   (car (cdr (cdr assoc-answer))))
  125.      (long-doc-string (car (cdr (cdr (cdr assoc-answer))))))
  126.  
  127.     (cond ((null assoc-answer)
  128.        (if (not suppress-errors)
  129.            (error "I don't know about %s" id)
  130.          nil))
  131.       ((and long-doc-string (not disallow-long-doc-strings))
  132.        (with-output-to-temp-buffer "*Method Description*"
  133.          (print long-doc-string)
  134.          (print-help-return-message)))
  135.       (result-string (message "%s"     
  136.                   (concat "method " method-name "(" 
  137.                       arg-string ") => " result-string)))
  138.       (t (message "%s" (concat "method " method-name "(" arg-string ")")))
  139. )))
  140.  
  141. ;;;;;;;;;;;;;;;;;;;;;;;;
  142.  
  143. ;; Methods, as they appear in the interim book..
  144. (defvar dylan-method-list '(
  145.      ("for" "..." nil
  146.       "for ( clauses  [{until | while} end-test] )
  147.   body
  148.   [finally result-body]
  149. end [for]    => values
  150.  
  151. variable = init-value then next-value
  152. variable [keyed-by key] in collection
  153. variable from start [{to | above | below} bound] [by increment]")
  154.      ("generic-function-methods" "generic-function" "sequence")
  155.      ("add-method" "generic-function, method" "new-method, old-method")
  156.      ("generic-function-mandatory-keywords" "generic-function" 
  157.       "collection-of-keywords-or-#f")
  158.      ("function-specializers" "function" 
  159.       "num-required-args, rest-boolean, kwd-sequence-or-#f")
  160.      ("applicable-method?" "function, #rest sample-args" "boolean")
  161.      ("sorted-applicable-methods" "generic-function, #rest sample-args"
  162.       "sequence1, sequence2")
  163.      ("find-method" "generic-function, specializer-list" "method-or-#f")
  164.      ("remove-method" "generic-function, method" "method")
  165.      ("make" "class, #key #all-keys" "instance")
  166.      ("initialize" "instance, #key #all-keys")
  167.      ("slot-initialized?" "instance, getter" "boolean")
  168.      ("instance?" "object, type" "boolean")
  169.      ("subtype?" "type1, type2" "boolean")
  170.      ("object-class" "object" "class")
  171.      ("all-superclasses" "class" "sequence")
  172.      ("direct-superclasses" "class" "sequence")
  173.      ("direct-subclasses" "class" "sequence")
  174.      ("as" "class, object" "instance")
  175.      ("shallow-copy" "object" "new-object")
  176.      ("class-for-copy" "object" "class")
  177.      ("size" "collection" "integer-or-#f")
  178.      ("empty?" "collection" "boolean")
  179.      ("do" "procedure, collection, #rest more-collections" "#f")
  180.      ("map" "procedure, collection, #rest more-collections" "new-collection")
  181.      ("map-as" "class, procedure, collection, #rest more-collections"
  182.       "new-collection")
  183.      ("map-into" 
  184.       "mutable-collection, procedure, collection, #rest more-collections"
  185.       "mutable-collection")
  186.      ("any?" "procedure, collection, #rest more-collections" "value")
  187.      ("every?" "procedure, collection, #rest more-collections" "boolean")
  188.      ("reduce" "procedure, initial-value, collection" "value")
  189.      ("reduce1" "procedure, collection" "value")
  190.      ("member?" "value, collection, #key test:" "boolean")
  191.      ("find-key" "collection, procedure, #key skip:, failure:" "key")
  192.      ("replace-elements!" 
  193.       "mutable-collection, predicate, new-value-fn, #key count:"
  194.       "mutable-collection")
  195.      ("fill!" "mutable-collection, value, #key start:, end:")
  196.      ("key-test" "collection" "test-function")
  197.      ("size-setter" "n, stretchy-sequence" "n")
  198.      ("add" "sequence, new-element" "new-sequence")
  199.      ("add!" "sequence1, new-element" "sequence2")
  200.      ("add-new" "sequence, new-element, #key test:" "new-sequence")
  201.      ("add-new!" "sequence, new-element, #key test:" "new-sequence")
  202.      ("remove" "sequence, value, #key test:, count:" "new-sequence")
  203.      ("remove!" "sequence, value, #key test:, count:" "new-sequence")
  204.      ("choose" "predicate, sequence" "new-sequence")
  205.      ("choose-by" "predicate, test-sequence, value-sequence"
  206.       "new-sequence")
  207.      ("intersection" "sequence1, sequence2, #key test:" "new-sequence")
  208.      ("union" "sequence1, sequence2, #key test:" "new-sequence")
  209.      ("remove-duplicates" "sequence, #key test:" "new-sequence")
  210.      ("remove-duplicates!" "sequence, #key test:" "new-sequence")
  211.      ("copy-sequence" "source, #key start:, end:" "new-sequence")
  212.      ("concatenate-as" "class, sequence1, #rest #rest more-sequences"
  213.       "new-sequence")
  214.      ("concatenate" "sequence1, #rest more-sequences" "new-sequence")
  215.      ("replace-subsequence!" "sequence, insert-sequence, #key start:, end:"
  216.       "result-sequence")
  217.      ("reverse" "sequence" "new-sequence")
  218.      ("reverse!" "sequence1" "sequence2")
  219.      ("sort" "sequence, #key test:, stable:" "new-sequence")
  220.      ("sort!" "sequence1, #key test:, stable:" "sequence2")
  221.      ("first" "sequence, #key default:" "value")
  222.      ("second" "sequence, #key default:" "value")
  223.      ("third" "sequence, #key default:" "value")
  224.      ("first-setter" "new-value, sequence" "new-value")
  225.      ("second-setter" "new-value, sequence" "new-value")
  226.      ("third-setter" "new-value, sequence" "new-value")
  227.      ("last" "sequence, #key default:" "value")
  228.      ("last-setter" "new-value, mutable-sequence" "new-value")
  229.      ("subsequence-position" "big-sequence, pattern, #key test:, count:"
  230.       "index")
  231.      ("dimensions" "array" "sequence")
  232.      ("rank" "array" "rank")
  233.      ("row-major-index" "array, #rest subscripts" "index")
  234.      ("aref" "array, #rest indices" "element")
  235.      ("aref-setter" "new-value, array, #rest indices" "new-value")
  236.      ("dimension" "array, axis" "dimension")
  237.      ("push" "deque, new-value" "deque")
  238.      ("pop" "deque" "first-element")
  239.      ("push-last" "deque, new-value" "deque")
  240.      ("pop-last" "deque" "first-element")
  241.      ("pair" "head, tail" "pair")
  242.      ("list" "#rest args" "list")
  243.      ("head" "list" "object")
  244.      ("tail" "list" "object")
  245.      ("head-setter" "object, pair" "object")
  246.      ("tail-setter" "object, pair" "object")
  247.      ("range" "#key from:, to:, above:, below:, by:, size:)" "range")
  248.      ("as-lowercase" "string-or-character" "new-string-or-character")
  249.      ("as-lowercase!" "string" "string")
  250.      ("as-uppercase" "string-or-character" "new-string-or-character")
  251.      ("as-uppercase!" "string" "string")
  252.      ("element" "collection, key, #key default:" "value")
  253.      ("element-setter" "value, mutable-collection, key" "value")
  254.      ("remove-key!" "table, key" "table")
  255.      ("vector" "#rest args" "vector")
  256.      ("forward-iteration-protocol" "collection" 
  257.       "init-state, limit, next, finished?, key, elt, elt-setter, copy-state"
  258.       "forward-iteration-protocol(collection) =>
  259.        init-state      :: <object>
  260.        limit           :: <object>
  261.        next-state(coll, state) => new-state
  262.        finished-state?(coll, state, limit) => boolean
  263.        current-key(coll, state) => key
  264.        current-element(coll, state) => element
  265.        current-elt-setter(value, coll, state) => value
  266.        copy-state(coll, state) => new-state")
  267.      ("backward-iteration-protocol" "collection" 
  268.       "final-state, limit, previous, finished?, key, elt, elt-setter, copy-state"
  269.       "backward-iteration-protocol(collection) =>
  270.        final-state      :: <object>
  271.        limit           :: <object>
  272.        previous-state(coll, state) => new-state
  273.        finished-state?(coll, state, limit) => boolean
  274.        current-key(coll, state) => key
  275.        current-element(coll, state) => element
  276.        current-elt-setter(value, coll, state) => value
  277.        copy-state(coll, state) => new-state")
  278.      ("table-protocol" "table" "test-function, hash-function"
  279.       "table-protocol(table) =>
  280.        test-function(key1, key2) => boolean
  281.        hash-function(key) => (id, state)")
  282.      ("merge-hash-codes" "id1, state1, id2, state2, #key ordered:"
  283.       "merged-id, merged-state")
  284.      ("odd?" "integer" "boolean")
  285.      ("even?" "integer" "boolean")
  286.      ("zero?" "integer" "boolean")
  287.      ("positive?" "integer" "boolean")
  288.      ("negative?" "integer" "boolean")
  289.      ("integral?" "integer" "boolean")
  290.      ("negative" "number" "number")
  291.      ("floor" "real" "integer, real")
  292.      ("ceiling" "real" "integer, real")
  293.      ("round" "real" "integer, real")
  294.      ("truncate" "real" "integer, real")
  295.      ("floor/" "real1, real2" "integer, real")
  296.      ("ceiling/" "real1, real2" "integer, real")
  297.      ("round/" "real1, real2" "integer, real")
  298.      ("truncate/" "real1, real2" "integer, real")
  299.      ("modulo" "real1, real2" "real")
  300.      ("remainder" "real1, real2" "real")
  301.      ("abs" "number" "number")
  302.      ("logior" "#rest integers" "integer")
  303.      ("logxor" "#rest integers" "integer")
  304.      ("logand" "#rest integers" "integer")
  305.      ("lognot" "#rest integers" "integer")
  306.      ("logbit?" "index, integer" "integer")
  307.      ("ash" "integer, count" "integer")
  308.      ("rationalize" "number" "number")
  309.      ("denominator" "number" "number")
  310.      ("lcm" "integer1, integer2" "integer")
  311.      ("gcd" "integer1, integer2" "integer")
  312.      ("min" "real, #rest more-reals" "real")
  313.      ("max" "real, #rest more-reals" "real")
  314.      ("compose" "function1, #rest more-functions" "function")
  315.      ("complement" "predicate" "function")
  316.      ("disjoin" "predicate1, #rest more-predicates" "function")
  317.      ("conjoin" "predicate1, #rest more-predicates" "function")
  318.      ("curry" "function, #rest curried-args" "new-function")
  319.      ("rcurry" "function, #rest curried-args" "new-function")
  320.      ("always" "object" "function")
  321.      ("apply" "function, #rest args" "values")
  322.      ("identity" "object" "object")
  323.      ("signal" "condition" "values")
  324.      ("error" "condition" "(will never return)")
  325.      ("cerror" "restart-description, condition" "#f")
  326.      ("break" "condition" "#f")
  327.      ("check-type" "value, type" "value-or-signals-error")
  328.      ("abort" "")
  329.      ("default-handler" "condition" "values")
  330.      ("restart-query" "restart")
  331.      ("return-query" "condition")
  332.      ("do-handlers" "funarg")
  333.      ("return-allowed?" "condition" "boolean")
  334.      ("return-description" "condition" "description")
  335. ))
  336.      
  337.